package android.team.app.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.team.app.R;
import android.team.app.utility.SmartDialogUtility;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageButton;
import android.widget.TextView;

public class BaseActivity extends Activity implements OnClickListener {
	protected TextView titleHeader;
	protected ImageButton btHome;
	protected Context baseActivity;

	protected ProgressDialog progressDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.base_activity);

		baseActivity = BaseActivity.this;

		loadUI();
	}

	// xay dung ham load UI rieng
	protected void loadUI() {
		titleHeader = (TextView) findViewById(R.id.titleHeader);
		btHome = (ImageButton) findViewById(R.id.btHome);
		btHome.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v == btHome) {
			startActivity(new Intent(baseActivity, FirstActivity.class));
		}
	}

	// viet phuong thuc xu li title
	protected void setTitleHeader(String title) {
		titleHeader.setText(title);
	}

	/**
	 * xay dung phuong thuc de hien thi progress khi load data
	 * 
	 * @param text
	 */
	public void showProgressDialog(String text) {
		if (progressDialog == null) {
			progressDialog = ProgressDialog.show(baseActivity, null, text);
			progressDialog.setCancelable(false);
		}
	}

	public void hideProgressDialog() {
		if (progressDialog != null) {
			progressDialog.cancel();
			progressDialog = null;
		}
	}

	public void showPositiveCustomDialog(Context context, int title,
			int message, int iconPositiveButton) {

		SmartDialogUtility dialog = new SmartDialogUtility(context, title,
				message, iconPositiveButton);

		WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
		lp.copyFrom(dialog.getWindow().getAttributes());
		lp.width = LayoutParams.WRAP_CONTENT;
		lp.height = LayoutParams.WRAP_CONTENT;
		dialog.show();
		dialog.getWindow().setAttributes(lp);
		
	}

}
